#ifndef  YAMLFILE_HPP
# define YAMLFILE_HPP

# include <string>
# include <vector>
# include <yaml.h>
# include "datatree.hpp"

namespace Yaml
{
  class YamlException : public std::exception
  {
  public:
    enum YamlError
    {
      ErrInitialize,
      ErrOpenFile,
      ErrSyntax
    };
    
    YamlException(YamlError code) : _code(code), _line(0), _col(0) {}
    YamlException(YamlError code, int l, int c) : _code(code), _line(l), _col(c) {}

    YamlError Code(void) const { return (_code); }
    int       Line(void) const { return (_line); }
    int       Col(void)  const { return (_col);  }

  private:
    YamlError _code;
    int       _line, _col;
  };

  class Parser
  {
  public:
    Parser(const std::string&);
    ~Parser();
    
    bool                        Run(void);
    DataTree*                   Parsed(unsigned int i = 0);

  private:
    DataBranch*                 ScalarEvent(const std::string&, DataBranch*, DataBranch*);

    unsigned char*              _buffer;
    std::vector<unsigned char*> _lines;
    yaml_parser_t               _parser;
    std::vector<DataTree*>      _parsed;
  };
}
#endif
